<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>BadgerDB: bufmgr/src/page_iterator.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">BadgerDB
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">bufmgr/src/page_iterator.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#pragma once</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;file.h&quot;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;page.h&quot;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &quot;types.h&quot;</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="keyword">namespace </span>badgerdb {
<a name="l00016"></a>00016 
<a name="l00023"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html">00023</a> <span class="keyword">class </span><a class="code" href="classbadgerdb_1_1_page_iterator.html" title="Iterator for iterating over the records in a page.">PageIterator</a> {
<a name="l00024"></a>00024  <span class="keyword">public</span>:
<a name="l00028"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#a612d51abd634209c03d672f1328bbc62">00028</a>   <a class="code" href="classbadgerdb_1_1_page_iterator.html#a612d51abd634209c03d672f1328bbc62">PageIterator</a>()
<a name="l00029"></a>00029       : page_(NULL) {
<a name="l00030"></a>00030     current_record_ = {<a class="code" href="classbadgerdb_1_1_page.html#a785a1e756d47fb7f8f3603a3fe8ffcef">Page::INVALID_NUMBER</a>, <a class="code" href="classbadgerdb_1_1_page.html#a4013fab43df72bc52931241575736353">Page::INVALID_SLOT</a>};
<a name="l00031"></a>00031   }
<a name="l00032"></a>00032 
<a name="l00039"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#a53cb54740042b01a78a0b033d8309d4a">00039</a>   <a class="code" href="classbadgerdb_1_1_page_iterator.html#a612d51abd634209c03d672f1328bbc62">PageIterator</a>(<a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>* page)
<a name="l00040"></a>00040       : page_(page)  {
<a name="l00041"></a>00041     assert(page_ != NULL);
<a name="l00042"></a>00042     <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> used_slot = <a class="code" href="classbadgerdb_1_1_page_iterator.html#a7b5eb61bcd7305f0aaa21e0f31d2f917">getNextUsedSlot</a>(<a class="code" href="classbadgerdb_1_1_page.html#a4013fab43df72bc52931241575736353">Page::INVALID_SLOT</a> <span class="comment">/* start */</span>);
<a name="l00043"></a>00043     current_record_ = {page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>(), used_slot};
<a name="l00044"></a>00044   }
<a name="l00045"></a>00045 
<a name="l00053"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#ad376a4999169f299874aa85252bca71b">00053</a>   <a class="code" href="classbadgerdb_1_1_page_iterator.html#a612d51abd634209c03d672f1328bbc62">PageIterator</a>(<a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>* page, <span class="keyword">const</span> <a class="code" href="structbadgerdb_1_1_record_id.html" title="Identifier for a record in a page.">RecordId</a>&amp; record_id)
<a name="l00054"></a>00054       : page_(page),
<a name="l00055"></a>00055         current_record_(record_id) {
<a name="l00056"></a>00056   }
<a name="l00057"></a>00057 
<a name="l00061"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#a2e63f3eea97170b2c566d1549a2215f0">00061</a>   <span class="keyword">inline</span> <a class="code" href="classbadgerdb_1_1_page_iterator.html" title="Iterator for iterating over the records in a page.">PageIterator</a>&amp; <a class="code" href="classbadgerdb_1_1_page_iterator.html#a2e63f3eea97170b2c566d1549a2215f0">operator++</a>() {
<a name="l00062"></a>00062     assert(page_ != NULL);
<a name="l00063"></a>00063     <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> used_slot = <a class="code" href="classbadgerdb_1_1_page_iterator.html#a7b5eb61bcd7305f0aaa21e0f31d2f917">getNextUsedSlot</a>(current_record_.<a class="code" href="structbadgerdb_1_1_record_id.html#a19ec7b749099499446fdd24d48cec9ef">slot_number</a>);
<a name="l00064"></a>00064     current_record_ = {page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>(), used_slot};
<a name="l00065"></a>00065 
<a name="l00066"></a>00066     <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00067"></a>00067   }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069   <span class="keyword">inline</span> <a class="code" href="classbadgerdb_1_1_page_iterator.html" title="Iterator for iterating over the records in a page.">PageIterator</a> <a class="code" href="classbadgerdb_1_1_page_iterator.html#a2e63f3eea97170b2c566d1549a2215f0">operator++</a>(<span class="keywordtype">int</span>) {
<a name="l00070"></a>00070     <a class="code" href="classbadgerdb_1_1_page_iterator.html" title="Iterator for iterating over the records in a page.">PageIterator</a> tmp = *<span class="keyword">this</span>;   <span class="comment">// copy ourselves</span>
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     assert(page_ != NULL);
<a name="l00073"></a>00073     <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> used_slot = <a class="code" href="classbadgerdb_1_1_page_iterator.html#a7b5eb61bcd7305f0aaa21e0f31d2f917">getNextUsedSlot</a>(current_record_.<a class="code" href="structbadgerdb_1_1_record_id.html#a19ec7b749099499446fdd24d48cec9ef">slot_number</a>);
<a name="l00074"></a>00074     current_record_ = {page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>(), used_slot};
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     <span class="keywordflow">return</span> tmp;
<a name="l00077"></a>00077   }
<a name="l00084"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#a1111e07de5972ffd9244e312ac938dac">00084</a>   <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classbadgerdb_1_1_page_iterator.html#a1111e07de5972ffd9244e312ac938dac">operator==</a>(<span class="keyword">const</span> <a class="code" href="classbadgerdb_1_1_page_iterator.html" title="Iterator for iterating over the records in a page.">PageIterator</a>&amp; rhs)<span class="keyword"> const </span>{
<a name="l00085"></a>00085     <span class="keywordflow">return</span> page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>() == rhs.page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>() &amp;&amp;
<a name="l00086"></a>00086         current_record_ == rhs.current_record_;
<a name="l00087"></a>00087   }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089   <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> <a class="code" href="classbadgerdb_1_1_page_iterator.html" title="Iterator for iterating over the records in a page.">PageIterator</a>&amp; rhs)<span class="keyword"> const </span>{
<a name="l00090"></a>00090     <span class="keywordflow">return</span> (page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>() != rhs.page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#af55a0b44876bff4d513bdbed8bc8c5a3">page_number</a>()) || 
<a name="l00091"></a>00091         (current_record_ != rhs.current_record_);
<a name="l00092"></a>00092   }
<a name="l00093"></a>00093 
<a name="l00100"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#a5e9f06b5a70663086720fd919a5b6bdb">00100</a>   <span class="keyword">inline</span> std::string <a class="code" href="classbadgerdb_1_1_page_iterator.html#a5e9f06b5a70663086720fd919a5b6bdb">operator*</a>()<span class="keyword"> const </span>{
<a name="l00101"></a>00101     <span class="keywordflow">return</span> page_-&gt;<a class="code" href="classbadgerdb_1_1_page.html#a77b352920c3e66384317bbcdcd900d99">getRecord</a>(current_record_); 
<a name="l00102"></a>00102   }
<a name="l00103"></a>00103 
<a name="l00111"></a><a class="code" href="classbadgerdb_1_1_page_iterator.html#a7b5eb61bcd7305f0aaa21e0f31d2f917">00111</a>   <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> <a class="code" href="classbadgerdb_1_1_page_iterator.html#a7b5eb61bcd7305f0aaa21e0f31d2f917">getNextUsedSlot</a>(<span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> start)<span class="keyword"> const </span>{
<a name="l00112"></a>00112     <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> slot_number = <a class="code" href="classbadgerdb_1_1_page.html#a4013fab43df72bc52931241575736353">Page::INVALID_SLOT</a>;
<a name="l00113"></a>00113     <span class="keywordflow">for</span> (<a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8" title="Identifier for a slot in a page.">SlotId</a> i = start + 1; i &lt;= page_-&gt;header_.<a class="code" href="structbadgerdb_1_1_page_header.html#a6c233369c611cfb617ba676e11a9d87d">num_slots</a>; ++i) {
<a name="l00114"></a>00114       <span class="keyword">const</span> <a class="code" href="structbadgerdb_1_1_page_slot.html" title="Slot metadata that tracks where a record is in the data space.">PageSlot</a>* slot = page_-&gt;getSlot(i);
<a name="l00115"></a>00115       <span class="keywordflow">if</span> (slot-&gt;<a class="code" href="structbadgerdb_1_1_page_slot.html#a4ea5ad6e73525244bb368181f21fd018">used</a>) {
<a name="l00116"></a>00116         slot_number = i;
<a name="l00117"></a>00117         <span class="keywordflow">break</span>;
<a name="l00118"></a>00118       }
<a name="l00119"></a>00119     }
<a name="l00120"></a>00120     <span class="keywordflow">return</span> slot_number;
<a name="l00121"></a>00121   }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123  <span class="keyword">private</span>:
<a name="l00127"></a>00127   <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>* page_;
<a name="l00128"></a>00128 
<a name="l00132"></a>00132   <a class="code" href="structbadgerdb_1_1_record_id.html" title="Identifier for a record in a page.">RecordId</a> current_record_;
<a name="l00133"></a>00133 
<a name="l00134"></a>00134 };
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Wed Jan 30 2013 14:17:57 for BadgerDB by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
